// index.js
const {answersListUrl} = require('../../apiConfig/apiList/luban')
Page({
  data: {
    pageNum: 1,
    pageSize: 10,
    isEnd: false,
    orderList:[
    ]

  },
  gotoDetail(e){
    let data = e.currentTarget.dataset
    wx.redirectTo({
      url: `/pages/maintenance-questions-detail/index?id=${data.id}`,
    })
  },
  onChange(event) {

  },
  onShow(){
    this.getOrderList();
  },

  onCancel() {
  },
  doClose() {
  },
  getOrderList(){
    if(this.data.isEnd)return;
    let that = this;
    let pageNum = this.data.pageNum;
    let pageSize = this.data.pageSize;
    let list = this.data.orderList;
    let params = {
      pageNum: pageNum,
      pageSize: pageSize,
      orderByColumn: 'create_time',
      isAsc: 'desc',
    };
    answersListUrl(params).then(res=>{
      if(res.code == 200){
        let data = res.rows;
        this.setData({
          orderList: list.concat(data)
        });
        if(res.tatal == 0){
          wx.showToast({
            title: '暂无维修维修！',
            icon: 'none',
            mask: true,
            success: () => {
              reject(err)
            }
          })
        }
        if(that.data.orderList.length < res.total){
          pageNum++;
          this.setData({
            pageNum
          })
        }else{
          this.setData({
            isEnd: 'ture'
          });
        }
      }
    })
  },
  onReachBottom() {
    console.log("维修问答....")
    if(!this.data.isEnd) {
      this.getOrderList();
    }else{
      wx.showToast({
        title: '已加载全部',
        icon: 'none',
        duration: 1000,
      })
    }
  },
})
